/**
 * Created by MetaLab_Gu on 2016/5/12.
 */
'use strict';
angular.module('metalabPartnerApp').directive('metaListFilterXs', function () {
    return {
        restrict: 'E',
        transclude: true,
        replace: true,
        templateUrl: 'views/common/listFilterXS.html',
        // scope: {
        //     config: '=',
        //     data: '=',
        //     head: '@'
        // },
        controller: 'listFilterCtrl'
    };
}).directive('metaListFilter', function () {
    return {
        restrict: 'E',
        transclude: true,
        replace: true,
        templateUrl: 'views/common/listFilter.html',
        // scope: {
        //     config: '=',
        //     data: '=',
        //     head: '@'
        // },
        controller: 'listFilterCtrl'
    };
}).directive('metaDropdown', ['$window', function ($window) {
    return {
        restrict: 'A',
        transclude: false,
        replace: false,
        link: function ($scope, $element) {
            var window = angular.element($window);

            //点击打开
            $element.bind('click', function (e) {
                $scope.isExpanded = !$scope.isExpanded;
                $scope.$apply();
                e.stopPropagation();
            });

            //点击关闭
            window.bind('click', function () {
                $scope.isExpanded = false;
                $scope.$apply();
            });
        }
    };
}]).controller('listFilterCtrl', ['$scope', function ($scope) {

    $scope.isCollapsed = false;
    //设置默认值
    // $scope.config = $scope.config ? $scope.config : {
    //     'chose': '不限',
    //     'showNumber': undefined
    // };

    // $scope.listIndex = $scope.config.chose;

    //分割隐藏部分
    // if ($scope.config.showNumber && $scope.config.showNumber !== 0) {
    //     $scope.data2 = $scope.data.splice($scope.config.showNumber, $scope.data.length - $scope.config.showNumber);
    //     $scope.listMoreIndex = ($scope.config.chose === '中国' || $scope.config.chose === '不限') ? ($scope.data2[0] || '更多') : $scope.config.chose;
    // }

    /**
     * @param [string] item [选中值]
     */
    // $scope.select = function (item) {
        // $scope.data2 ? $scope.listMoreIndex = $scope.data2[0] : '';
        // if ($scope.listIndex !== item) {
        //     $scope.listIndex = item;
        //     $scope.config.chose = $scope.listIndex;
        // }
    // };

    // $scope.ddSelect = function (item) {
    //     $scope.listMoreIndex = item;
    //     if ($scope.listIndex !== item) {
    //         $scope.listIndex = item;
    //         $scope.config.chose = $scope.listIndex;
    //     }
    // };

    $scope.removeSelected = function (item) {
        // console.log('delete', item);
    };
}]);
